package gintemplate

import (
	"github.com/elazarl/go-bindata-assetfs"
)

func FileHandlerBinData(asset *assetfs.AssetFS) FileHandler {
	return func(config TemplateConfig, tplFile string) (content string, err error) {
		var bts []byte
		bts, err = asset.Asset(tplFile + config.Extension)
		content = string(bts)
		return
	}
}

func NewBinDataWithConfig(asset *assetfs.AssetFS, config TemplateConfig) *TemplateEngine {
	engine := New(config)
	engine.SetFileHandler(FileHandlerBinData(asset))
	return engine
}

func NewBinData(asset *assetfs.AssetFS) *TemplateEngine {
	return NewBinDataWithConfig(asset, DefaultConfig)
}
